//
//  HLIntimacyListCell.m
//  YueYue
//
//  Created by hulu001 on 2023/6/16.
//

#import "HLIntimacyListCell.h"

@interface HLIntimacyListCell ()

@property (nonatomic, strong) UIImageView *avatarView;
@property (nonatomic, strong) UILabel *nicknameLabel;
@property (nonatomic, strong) QMUILabel *levelLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UILabel *timeLabel;

@end

@implementation HLIntimacyListCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = UIColorWhite;
        [self setupUI];
    }
    return self;
}


- (void)setupUI
{
    self.avatarView = [[UIImageView alloc] init];
    _avatarView.layer.cornerRadius = 30;
    _avatarView.layer.masksToBounds = YES;
    _avatarView.image = [HLUIHelper avatarPlaceholder];
    [self.contentView addSubview:_avatarView];
    [_avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(60);
        make.left.mas_equalTo(12);
        make.top.mas_equalTo(12);
        make.bottom.mas_equalTo(-12);
    }];
    
    
    self.nicknameLabel = [[UILabel alloc] init];
    _nicknameLabel.textColor = HLTextColor1;
    _nicknameLabel.text = @"聊人生阿姨有没有啊";
    _nicknameLabel.font = UIFontMediumMake(15);
    [self.contentView addSubview:_nicknameLabel];
    [_nicknameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_avatarView.mas_right).offset(12);
        make.top.equalTo(_avatarView).offset(8);
        make.right.mas_lessThanOrEqualTo(-184);
    }];
    
    self.levelLabel = [[QMUILabel alloc] qmui_initWithFont:UIFontBoldMake(11) textColor:UIColorWhite];
    _levelLabel.contentEdgeInsets = UIEdgeInsetsMake(2, 4, 2, 4);
    _levelLabel.backgroundColor = HLMainColor;
    _levelLabel.layer.masksToBounds = YES;
    _levelLabel.layer.cornerRadius = 4;
    [self.contentView addSubview:_levelLabel];
    [_levelLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_nicknameLabel.mas_right).offset(4);
        make.centerY.equalTo(_nicknameLabel);
    }];
    
    
    self.contentLabel = [[UILabel alloc] init];
    _contentLabel.font = UIFontMake(12);
    _contentLabel.textColor = HLTextColor2;
    _contentLabel.numberOfLines = 1;
    _contentLabel.text = @"错误的决定比没有决定要好";
    [self.contentView addSubview:_contentLabel];
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_nicknameLabel);
        make.bottom.equalTo(_avatarView).offset(-8);
        make.right.mas_equalTo(-104);
    }];
    
    
    self.timeLabel = [[UILabel alloc] qmui_initWithFont:UIFontMake(12) textColor:HLTextColor3];
    _timeLabel.text = @"12:32";
    [self.contentView addSubview:_timeLabel];
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-12);
        make.centerY.equalTo(_nicknameLabel);
    }];
}


- (void)setModel:(HLIntimacyModel *)model
{
    _model = model;
    
    [_avatarView sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[HLUIHelper avatarPlaceholder]];
    _nicknameLabel.text = model.nickName;
    _levelLabel.text = [NSString stringWithFormat:@"LV %@", model.intimacyLevel ? model.intimacyLevel : @"0"];
    _contentLabel.text = model.selfSign;
    _timeLabel.text = [HLHelper showDateString:model.cteTime];
}

- (void)chatAction
{
    [HLUIHelper chatWithUserId:_model.userId controller:self.qmui_viewController];
}


@end
